import { request } from '@/utils/request'

import type { EditableReqData, PageResult } from './model/common'
import type { TicketContentPageReqParams, TicketContentReqData, TicketContentRes, TicketPageReqParams, TicketReqData, TicketRes } from './model/ticket'

export function getTicketPageList(params: TicketPageReqParams) {
  return request.get<PageResult<TicketRes>>({ url: `/v1/ticket/page`, params })
}

export function getTicketDetail(id: string) {
  return request.get<TicketRes>({ url: `/v1/ticket`, params: { id } })
}

export function createTicket(data: TicketReqData) {
  return request.post<TicketRes>({ url: `/v1/save/ticket`, data })
}

export function updateTicket(data: EditableReqData<TicketReqData>) {
  return request.post<TicketRes>({ url: `/v1/save/ticket`, data })
}

export function getTicketContentPageList(params: TicketContentPageReqParams) {
  return request.get<PageResult<TicketContentRes>>({ url: `/v1/content/page`, params })
}

export function getTicketContentDetail(id: string) {
  return request.get<TicketContentRes>({ url: `/v1/content`, params: { id } })
}

export function createTicketContent(data: TicketContentReqData) {
  return request.post<TicketContentRes>({ url: `/v1/save/content`, data })
}

export function updateTicketContent(data: EditableReqData<TicketContentReqData>) {
  return request.post<TicketContentRes>({ url: `/v1/save/content`, data })
}
